package tantque;

import static tantque.Echiquier.*;

public class Etat {

    private IPredicat B1,  B2,  B3;
    private IFermeture succ1,  succ2,  succ3;
    private IFermeture E;
    private Direction directionCourante = Direction.nord;
    private int indexDirCourante = Direction.nord.ordinal();
    private Case caseCourante = Case.a1;
    private int indexCaseCourante = Case.a1.ordinal();
    private Case caseCandidate;
    private final Echiquier echiquier = Echiquier.getInstance();

    public Etat() {

        B1 = new IPredicat() {

            @Override
            public boolean evaluer() {
                return caseCourante != Case.h8;
            }
        };
        succ1 = new IFermeture() {

            @Override
            public void executer() {
                caseCourante = Case.values()[++indexCaseCourante];

            }
        };
        B2 = new IPredicat() {

            @Override
            public boolean evaluer() {
                if (directionCourante == Direction.nord_nord_ouest) {
                    directionCourante = Direction.nord;
                    indexDirCourante = 0;
                    return false;
                }

                return true;

            }
        };
        succ2 = new IFermeture() {

            @Override
            public void executer() {
                directionCourante = Direction.values()[indexDirCourante++];
                caseCandidate = caseCourante;
            }
        };
        B3 = new IPredicat() {

            @Override
            public boolean evaluer() {
                return Echiquier.getCASES()[valeur(caseCandidate) + directionCourante.valeur()] == HORS_JEU;
            }
        };
        succ3 = new IFermeture() {

            @Override
            public void executer() {
                caseCandidate = Echiquier.nom(Echiquier.valeur(caseCandidate) + directionCourante.valeur());
            }
        };

        E = new IFermeture() {

            @Override
            public void executer() {
                System.out.println(caseCourante + ":" +
                        directionCourante.name() + "," +
                        caseCandidate + ",");
            }
        };

        WhileThree.getInstance(B1, B2, B3, succ1, succ2, succ3, E).executer();
    }
}












